﻿#region using...
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
#endregion

namespace Infusion.Silverlight.Controls.Ribbon
{
    #region : RibbonStackPanel :
    public class RibbonStackPanel : StackPanel, IRibbonTabGroupItem
    {
        #region Class Variables...
        private RibbonTabGroup ribbonTabGroup;
        private bool layoutUpdated = false;
        #endregion

        #region Constructor(s)...
        #region RibbonStackPanel
        public RibbonStackPanel() : base()
        {
            Orientation = Orientation.Horizontal;
            LayoutUpdated += new EventHandler(RibbonStackPanel_LayoutUpdated);
        }
        #endregion
        #endregion

        #region Event Handlers...
        #region RibbonStackPanel_LayoutUpdated
        private void RibbonStackPanel_LayoutUpdated(object sender, EventArgs e)
        {
            if (!layoutUpdated)
            {
                for (int i = 0; i < Children.Count; i++)
                {
                    Thickness currentThickness = (Thickness)Children[i].GetValue(FrameworkElement.MarginProperty);
                    Children[i].SetValue(FrameworkElement.MarginProperty, new Thickness(currentThickness.Left,
                        currentThickness.Top,
                        currentThickness.Right + (i == Children.Count - 1 ? 0 : 3),
                        currentThickness.Bottom));

                    if (Children[i] is IRibbonTabGroupItem)
                        ((IRibbonTabGroupItem)Children[i]).ParentRibbonTabGroup = ParentRibbonTabGroup;
                }

                layoutUpdated = true;
            }
        }
        #endregion
        #endregion

        #region Properties...
        #region ParentRibbonTabGroup
        public RibbonTabGroup ParentRibbonTabGroup
        {
            get { return ribbonTabGroup; }
            set { ribbonTabGroup = value; }
        }
        #endregion

        #region RibbonTabGroupItemRowSpan
        public RibbonTabGroupItemRowSpan RibbonTabGroupItemRowSpan
        {
            get { return RibbonTabGroupItemRowSpan.One; }
        }
        #endregion
        #endregion
    }
    #endregion
}
